package com.slorgs.business.utils

import com.slorgs.infrastructure.model.User
import java.util.HashMap

class ThreadLocalUtil {

    companion object {
        private val mapThreadLocal = ThreadLocal<MutableMap<String, Any>>()
        fun put(k: String, v: Any) {
            var map = mapThreadLocal.get()
            if (map == null) {
                map = HashMap()
            }
            map[k] = v
            mapThreadLocal.set(map)
        }

        fun getUser(): User? {
            return get("CURRENT_USER") as User?
        }

        operator fun get(key: String): Any? {
            val item: Map<String, Any>? = mapThreadLocal.get()
            var result: Any? = null
            if (item != null) {
                result = item[key]
            }
            return result
        }
    }
}